package cn.itsource.pay.service.impl;

import cn.itsource.basic.service.impl.BasicServiceImpl;
import cn.itsource.basic.util.AliPayUtil;
import cn.itsource.pay.domain.AlipayInfo;
import cn.itsource.pay.domain.PayBill;
import cn.itsource.pay.mapper.AlipayInfoMapper;
import cn.itsource.pay.mapper.PayBillMapper;
import cn.itsource.pay.service.IAlipayInfoService;
import cn.itsource.pay.service.IPayBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PayBillServiceImpl extends BasicServiceImpl<PayBill> implements IPayBillService {

    @Autowired
    private AlipayInfoMapper alipayInfoMapper;

    @Autowired
    private PayBillMapper payBillMapper;
    //进行支付的渠道分发
    @Override
    public String goPay(PayBill payBill) {
        //判断 用户选中的支付方式
        switch (payBill.getPayChannel().intValue()){
            case 0://余额支付
                return null;
            case 1://支付宝支付
                AlipayInfo alipayInfo =  alipayInfoMapper.loadByShopId(27L);
                String pay = AliPayUtil.aliPay(alipayInfo, payBill);
                return pay;
            case 2://微信支付
                return null;
            case 3: //银联支付
                return null;
        }

        return  null;
    }

    @Override
    public PayBill loadByOrderSn(String out_trade_no) {
        return payBillMapper.loadByOrderSn(out_trade_no);
    }
}
